<?php

class Soul_Db_Factory {

    private static $_drivers = array();
    //private static $_transactions = array();

    public static function getDriver($name = NULL) {
        $connection = Soul_Config::getConnectionString($name, TRUE);
        if (!isset(self::$_drivers[$connection['name']])){
            $result = Soul_Loader::loadInstance(
            	$connection['driver'], 
            	array(
            		$connection['server'],
            		$connection['database'],
            		$connection['username'],
            		$connection['password']
            	)
            );
            $result->connect();
            self::$_drivers[$connection['name']] = $result;
        }
        return self::$_drivers[$connection['name']];
    }

    /*
    public static function getTransaction($connectionName = NULL) {
        $connectionName = is_null($connectionName) ? Soul_Db_Config::getDefaultConnection() : $connectionName;
        return new Soul_Db_Transaction(self::getDriver($connectionName));
    }
    */
    
    public static function createQuery(){
    	return Soul_Loader::loadInstance('db_sql_query');
    }
    
    public static function createInsert(){
    	return Soul_Loader::loadInstance('db_sql_insert');
    }    
    
    public static function createUpdate(){
    	return Soul_Loader::loadInstance('db_sql_update');
    }
    
    public static function createDelete(){
    	return Soul_Loader::loadInstance('db_sql_delete');
    }   
}

